import React from 'react';

import {App, Index, Grade, Webinfo, System} from './containers';

import {Bundle, Loading} from './components';

/**
 * 将组件封装成为异步加载组件
 *
 * @param {Object<React.component>} component 待封装组件
 * @param {Object} props 组件属性对象
 * @return {Function} 组件创建方法
 */
function lazyLoad(component = null, props = {}) {
    return props => (
        <Bundle load={component}>
            {WrappedComponent => (
                WrappedComponent ? <WrappedComponent {...props} /> : <Loading />
            )}
        </Bundle>
    );
}

export default [
    {
        path: '/',
        exact: true,
        component: lazyLoad(Index)
    },
    {
        component: App,
        routes: [
            {
                path: '/system',
                exact: true,
                component: lazyLoad(System)
            },
            {
                path: '/grade',
                exact: true,
                component: lazyLoad(Grade)
            },
            {
                path: '/webinfo',
                exact: true,
                component: lazyLoad(Webinfo)
            }
        ]
    }
];
